<template>
  <div class="home">
    <GeoLocation @search-error="handleSearchError"/>
    <div v-if="loading" class="loading">加载中...</div>
    <template v-else>
      <FutureWeather />
      <LifeIndex />
    </template>
    <div v-if="error" class="error-toast">{{ error }}</div>
  </div>
</template>

<script>
import GeoLocation from '@/components/GeoLocation.vue'
import FutureWeather from '@/components/FutureWeather.vue'
import LifeIndex from '@/components/LifeIndex.vue'

export default {
  name: 'HomeView',
  components: {
    GeoLocation,
    FutureWeather,
    LifeIndex
  },
  data() {
    return {
      loading: false,
      error: ''
    }
  },
  methods: {
    handleSearchError(message) {
      this.error = message;
      setTimeout(() => {
        this.error = '';
      }, 3000);
    }
  }
}
</script>

<style scoped>
.home {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  position: relative;
}

.home > * {
  margin-bottom: 20px;
}

.loading {
  text-align: center;
  padding: 20px;
  color: #666;
}

.error-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #ff5252;
  color: white;
  padding: 10px 20px;
  border-radius: 4px;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 768px) {
  .home {
    padding: 10px;
  }
}
</style>
